import { getBaseUrl } from '@/services/urlconst';
import { getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';

export const taskPushService = (callback) => {
  const request: any = useRequest(
    (payload: any) => {
      let reqParams = {
        current: 1,
        pageSize: 10,
        sysCode: 'ZYKYPT-SXSQ-006',
        sort: 'receiveDateTime',
        receiver: getUserID(),
        ...payload,
      };
      if (reqParams?.endTime) {
        const [endTimeStart, endTimeEnd] = reqParams.endTime;
        reqParams['endTimeStart'] = endTimeStart.format('YYYY-MM-DD 00:00:00');
        reqParams['endTimeEnd'] = endTimeEnd.format('YYYY-MM-DD 23:59:59');
        delete reqParams['endTime'];
      }
      if (reqParams?.createDateTime) {
        const [createTimeStart, createTimeEnd] = reqParams.createDateTime;
        reqParams['createDateTimeStart'] = createTimeStart.format('YYYY-MM-DD 00:00:00');
        reqParams['createDateTimeEnd'] = createTimeEnd.format('YYYY-MM-DD 23:59:59');
        delete reqParams['createDateTime'];
      }
      let reqUrl = `${getBaseUrl()}/taskPushController/dataGrid`;
      return requestFunComponFiex('POST', reqUrl, reqParams);
    },
    {
      manual: true,
      paginated: true,
      defaultPageSize: 10,
      onSuccess: callback,
    },
  );
  return {
    taskPushRun: request.run,
    taskPushLoading: request.loading,
    taskPushPagination: request.pagination,
  };
};
